//
//  SQHomeViewController.m
//  energy
//
//  Created by 周曼迪 on 2021/7/6.
//

#import "SQHomeViewController.h"

#import "SDCycleScrollView.h"

#import "SQListViewController.h"
#import "SQConfirmViewController.h"
#import "SQAcceptanceViewController.h"
#import "SQRectificationViewController.h"
#import "SQHomeWorkViewController.h"
#import "SQSpecialViewController.h"
#import "SQNewDetailsViewController.h"


#import "SQNewModel.h"
#import "SQHomeModel.h"

@interface SQHomeViewController ()<BaseCollectionVCInterface,SDCycleScrollViewDelegate>
/**广告*/
@property (weak, nonatomic) IBOutlet UIView *view_advertising;
@property (strong,nonatomic) NSMutableArray *bannerArr;
@property (strong, nonatomic) SQHomeModel *homeModel;
@property (strong, nonatomic) SDCycleScrollView *cycleScrollView;
@property ( strong ,nonatomic) SQNewModel *SnewModel;
@end

@implementation SQHomeViewController

-(NSMutableArray * )bannerArr{
    if (!_bannerArr) {
        _bannerArr = [[NSMutableArray alloc]init];
    }
    return _bannerArr;
}

- (void)viewDidLoad {
    self.collectionInterface = self;
    [super viewDidLoad];
    self.hidNav = YES;
    
   
    
    [self getData];
    
    self.collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self getData];
    }];
    
    [self initBananerScroller];
    LC_WEAK_SELF
    self.cellEvent = ^(int key, NSString * value) {

        if ([value isEqualToString:@"隐患列表"]) {
            SQListViewController * listVC = SQListViewController.new;
            [weakSelf pushVC:listVC];
        }else if ([value isEqualToString:@"隐患确认"]) {
            SQConfirmViewController * confirmVC = SQConfirmViewController.new;
            [weakSelf pushVC:confirmVC];
        }else if ([value isEqualToString:@"隐患整改"]) {
            SQRectificationViewController * rectificationVC =  SQRectificationViewController.new;
            [weakSelf pushVC:rectificationVC];
        }else if ([value isEqualToString:@"隐患验收"]) {
            SQAcceptanceViewController * acceptanceVC = SQAcceptanceViewController.new;
            [weakSelf pushVC:acceptanceVC];
        }else if ([value isEqualToString:@"作业检查"]) {
            SQHomeWorkViewController * homeWorkVC = SQHomeWorkViewController.new;
            [weakSelf pushVC:homeWorkVC];
            
        }else if ([value isEqualToString:@"专项检查"]) {
            SQSpecialViewController * specialVC = SQSpecialViewController.new;
            [weakSelf pushVC:specialVC];
        }
    };

}




#pragma mark -  构建轮播
- (void)initBananerScroller{
    self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, W(355), W(145)) imageURLStringsGroup:@[]];
    self.cycleScrollView.delegate = self;
    self.cycleScrollView.backgroundColor = [UIColor whiteColor];
//    [self.cycleScrollView SQCornerLineWidth:1 LineColor:[UIColor colorNamed:@"f1Color"]];
//    [self.cycleScrollView SQCornerRadius:5];
    self.cycleScrollView.layer.shadowOpacity = 1;
    self.cycleScrollView.layer.shadowOpacity = 0.2;
    self.cycleScrollView.infiniteLoop = NO;
    if (self.bannerArr.count == 1) {
        self.cycleScrollView.autoScroll = NO;
    }else{
        self.cycleScrollView.autoScroll = YES;
    }

    self.cycleScrollView.autoScrollTimeInterval = 3;

    self.cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleNone;
    [self.view_advertising addSubview:self.cycleScrollView];

    
}

//


- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
    if (self.SnewModel.data.count != 0) {
        SQNewModelData * dataModel = self.SnewModel.data[index];
        
        SQNewDetailsViewController * newDetailsVC = SQNewDetailsViewController.new;
        newDetailsVC.a_id = dataModel.a_id;
        [self pushVC:newDetailsVC];
    }
   
}


-(void)getData{
    [self.bannerArr removeAllObjects];
    [SQHomeModel getDataWithParams:@{@"m_id":UID,@"m_level":MLevel,@"m_one":MOne} HUD:NO WithCallBack:^(SQHomeModel * data) {
        self.homeModel = data;
        [SQNewModel getDataWithParams:@{@"ae_e":MEnterpriseId,@"a_type":@"1"}  WithCallBack:^(SQNewModel * data) {
            if (data.data.count == 0) {
                self.cycleScrollView.localizationImageNamesGroup = @[@"banner"];
            }else{
                self.SnewModel = data;
                 for (SQNewModelData * homeBannerModel in data.data) {
                     [self.bannerArr addObject:[NSString stringWithFormat:@"http://government.anjiesws.com%@",homeBannerModel.a_img]];
                     
                     self.cycleScrollView.imageURLStringsGroup = self.bannerArr;
                     
                 }
               
            }
            
            
            
        }];
        
      
        [self reloadCollectionView];
        [self.collectionView.mj_header endRefreshing];
        
    }];
}


-(NSInteger)sectionCount{
    return 1;
}

-(NSInteger)itemsCount:(NSInteger)section{
    if ([MLevel isEqualToString:@"1"] || [MLevel isEqualToString:@"4"]) {
        return 4;
    }else{
        return 6;
    }
    
    
}

-(NSArray<NSArray<NSString *> *> *)classArr{
            
    return @[@[@"SQHomeCollectionViewCell"]];
    
}

- (__kindof BaseModel *)modelForCell:(NSIndexPath *)indexPath{
    return self.homeModel;
   
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
